package main

import (
	"fmt"
	"github.com/flike/kingshard/backend"
	"github.com/flike/kingshard/mysql"
)

func newConn(addr string, user string, pass string) *backend.Conn {
	c := new(backend.Conn)
	if err := c.Connect(addr, user, pass, ""); err != nil {
		fmt.Println("Connect failed ____________________")
	} else {
		fmt.Println("Connect success ____________________")
	}
	return c
}

func (c *Conn) ShowMasterStatus(com string) (string, uint64, error) {
	var res *mysql.Result
	res, err := c.exec(com)
	if err != nil {
		panic(err)
	}

	var n = len(res.Resultset.Values)
	if n == 1 {
		fileStr, _ := res.Resultset.GetValue(0, 0)
		posStr, _ := res.Resultset.GetValue(0, 1)
		fileStrV, okf := fileStr.(string)

		if !okf {
			panic(err)
		}

		posStrV, okp := posStr.(uint64)
		if !okp {
			panic(err)
		}
		return fileStrV, posStrV, nil
	}
	return "", 0, fmt.Errorf("invalid resultset")
}
